package com.vgemv.jsutilitysdk.log;


import com.vgemv.jsutilitysdk.Time2.JsTimeManager;

public class JsLogEvent {

    static public int smi_index = 0;
    public int logLevel;
    public String message;
    public String context;
    public String fullTimeString;
    public int logTarget;
    public static final String defaultContext = "-";
    public Boolean isPlain = false;
    private String logContent;

    public JsLogEvent(String message, int logLevel, String context, int logTarget) {
        this.fullTimeString = JsTimeManager.sharedInstance.stdTimeStringForNow();
        if(context != null && context.length()>0) {
            this.context = context;
        }
        else {
            this.context = defaultContext;
        }
        this.message = message;
        this.logLevel = logLevel;
        this.logTarget = logTarget;
    }

    public String getLogContent() {
        if(logContent == null) {
            if(isPlain) {
                logContent = this.message;
            }
            else {
                //自动多添加一个换行.
                logContent = String.format("[%s][%s][%s]:%s\n",fullTimeString,logLevelString(),this.context,message);
            }
        }
        return logContent;
    }

    public String logLevelString() {
        switch (logLevel) {
            case JsLogManager.JsLogLevelVerbose:
                return "Verbose";
            case JsLogManager.JsLogLevelInfo:
                return "Info";
            case JsLogManager.JsLogLevelDebug:
                return "Debug";
            case JsLogManager.JsLogLevelWarn:
                return "Warn";
            case JsLogManager.JsLogLevelError:
                return "Error";
            case JsLogManager.JsLogLevelFatal:
                return "Fatal";
            default:
                return "";
        }
    }
}
